home *** CD-ROM | disk | FTP | other *** search
Wrap
SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++)))) SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++)))) NNNNAAAAMMMMEEEE strstreambuf - streambuf specialized to arrays SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS #include <iostream.h> #include <strstream.h> class strstreambuf : public streambuf { public: strstreambuf() ; strstreambuf(char*, int, char*); strstreambuf(int); strstreambuf(unsigned char*, int, unsigned char*); strstreambuf(void* (*a)(long), void(*f)(void*)); void freeze(int n=1) ; char* str(); virtual streambuf* setbuf(char*, int) }; DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN A _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff is a _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff that uses an array of bytes (a string) to hold the sequence of characters. Given the convention that a _cccc_hhhh_aaaa_rrrr_**** should be interpreted as pointing just before the _cccc_hhhh_aaaa_rrrr it really points at, the mapping between the abstract get/put pointers (see _ssss_bbbb_uuuu_ffff_...._pppp_uuuu_bbbb(3C++)) and _cccc_hhhh_aaaa_rrrr_**** pointers is direct. Moving the pointers corresponds exactly to incrementing and decrementing the _cccc_hhhh_aaaa_rrrr_**** values. To accommodate the need for arbitrary length strings _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff supports a dynamic mode. When a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff is in dynamic mode, space for the character sequence is allocated as needed. When the sequence is extended too far, it will be copied to a new array. In the following descriptions assume: - _s_s_b is a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_****. - _n is an _iiii_nnnn_tttt. - _p_t_r and _p_s_t_a_r_t are _cccc_hhhh_aaaa_rrrr_****s or _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _cccc_hhhh_aaaa_rrrr_****s. - _a is a _vvvv_oooo_iiii_dddd_**** _((((_****_))))_((((_llll_oooo_nnnn_gggg_)))). - _f is a _vvvv_oooo_iiii_dddd_**** _((((_****_))))_((((_vvvv_oooo_iiii_dddd_****_)))). CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss:::::::: _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_((((_)))) Constructs an empty _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff in dynamic mode. This means that space will be automatically allocated to accommodate the characters that are put into the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff (using operators _nnnn_eeee_wwww and _dddd_eeee_llll_eeee_tttt_eeee). Because this may require copying the original characters, it is recommended that when many characters will be inserted, the program should use _ssss_eeee_tttt_bbbb_uuuu_ffff_((((_)))) (described below) to inform the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff. PPPPaaaaggggeeee 1111 SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++)))) SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++)))) _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_((((_a_,,,, _f_)))) Constructs an empty _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff in dynamic mode. _a is used as the allocator function in dynamic mode. The argument passed to _a will be a _llll_oooo_nnnn_gggg denoting the number of bytes to be allocated. If _a is null, _oooo_pppp_eeee_rrrr_aaaa_tttt_oooo_rrrr _nnnn_eeee_wwww will be used. _f is used to free (or delete) areas returned by _a. The argument to _f will be a pointer to the array allocated by _a. If _f is null, _oooo_pppp_eeee_rrrr_aaaa_tttt_oooo_rrrr _dddd_eeee_llll_eeee_tttt_eeee is used. _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_((((_n_)))) Constructs an empty _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff in dynamic mode. The initial allocation of space will be at least _n bytes. _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_((((_p_t_r_,,,, _n_,,,, _p_s_t_a_r_t_)))) Constructs a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff to use the bytes starting at _p_t_r. The _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff will be in static mode; it will not grow dynamically. If _n is positive, then the _n bytes starting at _p_t_r are used as the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff. If _n is zero, _p_t_r is assumed to point to the beginning of a null terminated string and the bytes of that string (not including the terminating null character) will constitute the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff. If _n is negative, the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff is assumed to continue indefinitely. The get pointer is initialized to _p_t_r. The put pointer is initialized to _p_s_t_a_r_t. If _p_s_t_a_r_t is null, then stores will be treated as errors. If _p_s_t_a_r_t is non-null, then the initial sequence for fetching (the get area) consists of the bytes between _p_t_r and _p_s_t_a_r_t. If _p_s_t_a_r_t is null, then the initial get area consists of the entire array. MMMMeeeemmmmbbbbeeeerrrr ffffuuuunnnnccccttttiiiioooonnnnssss:::: _s_s_b_----_>>>>_ffff_rrrr_eeee_eeee_zzzz_eeee_((((_n_)))) Inhibits (when _n is nonzero) or permits (when _n is zero) automatic deletion of the current array. Deletion normally occurs when more space is needed or when _s_s_b is being destroyed. Only space obtained via dynamic allocation is ever freed. It is an error (and the effect is undefined) to store characters into a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff that was in dynamic allocation mode and is now frozen. It is possible, however, to thaw (unfreeze) such a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff and resume storing characters. _p_t_r_====_s_s_b_----_>>>>_ssss_tttt_rrrr_((((_)))) Returns a pointer to the first _cccc_hhhh_aaaa_rrrr of the current array and freezes _s_s_b. If _s_s_b was constructed with an explicit array, _p_t_r will point to that array. If _s_s_b is in dynamic allocation mode, but nothing has yet been stored, _p_t_r may be null. _s_s_b_----_>>>>_ssss_eeee_tttt_bbbb_uuuu_ffff_((((_0000_,,,,_n_)))) _s_s_b remembers _n and the next time it does a dynamic mode allocation, it makes sure that at least _n bytes are allocated. PPPPaaaaggggeeee 2222 SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++)))) SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++)))) SSSSEEEEEEEE AAAALLLLSSSSOOOO _ssss_bbbb_uuuu_ffff_...._pppp_uuuu_bbbb(3C++), _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm(3C++) PPPPaaaaggggeeee 3333